
include(CheckTypeSize)
check_type_size("char" SIZEOF_CHAR)
check_type_size("float" SIZEOF_FLOAT)
check_type_size("int" SIZEOF_INT)
check_type_size("intmax_t" SIZEOF_INTMAX_T)
check_type_size("intptr_t" SIZEOF_INTPTR_T)
check_type_size("long" SIZEOF_LONG)
check_type_size("long long" SIZEOF_LONG_LONG)
check_type_size("off_t" SIZEOF_OFF_T)
check_type_size("ptrdiff_t" SIZEOF_PTRDIFF_T)
check_type_size("short" SIZEOF_SHORT)
check_type_size("size_t" SIZEOF_SIZE_T)
check_type_size("uintptr_t" SIZEOF_UINTPTR_T)
check_type_size("unsigned char" SIZEOF_UNSIGNED_CHAR)
check_type_size("unsigned int" SIZEOF_UNSIGNED_INT)
check_type_size("unsigned long" SIZEOF_UNSIGNED_LONG)
check_type_size("unsigned long long" SIZEOF_UNSIGNED_LONG_LONG)
check_type_size("unsigned short" SIZEOF_UNSIGNED_SHORT)
check_type_size("unsigned __int64" SIZEOF_UNSIGNED___INT64)
check_type_size("void *" SIZEOF_VOID_P)
check_type_size("__int64" SIZEOF___INT64)
check_type_size("complex double" SIZEOF_COMPLEX_DOUBLE)
if(NOT SIZEOF___INT64)
    set(SIZEOF___INT64 0)
endif()
if(NOT SIZEOF_UNSIGNED___INT64)
    set(SIZEOF_UNSIGNED___INT64 0)
endif()
if(SIZEOF_COMPLEX_DOUBLE)
    set(HAVE_COMPLEX_DOUBLE 1)
endif()
include (CheckIncludeFile)
check_include_file (alloca.h HAVE_ALLOCA_H)
check_include_file (complex.h HAVE_COMPLEX_H)
check_include_file (crt_externs.h HAVE_CRT_EXTERNS_H)
check_include_file (crypt.h HAVE_CRYPT_H)
check_include_file (assert.h HAVE_ASSERT_H)
check_include_file (direct.h HAVE_DIRECT_H)
check_include_file (dirent.h HAVE_DIRENT_H)
check_include_file (dlfcn.h HAVE_DLFCN_H)
check_include_file (fenv.h HAVE_FENV_H)
check_include_file (floatingpoint.h HAVE_FLOATINGPOINT_H)
check_include_file (grp.h HAVE_GRP_H)
check_include_file (ieeefp.h HAVE_IEEEFP_H)
check_include_file (inttypes.h HAVE_INTTYPES_H)
check_include_file (io.h HAVE_IO_H)
check_include_file (libc.h HAVE_LIBC_H)
check_include_file (limits.h HAVE_LIMITS_H)
check_include_file (machine/fpu.h HAVE_MACHINE_FPU_H)
check_include_file (malloc.h HAVE_MALLOC_H)
check_include_file (memory.h HAVE_MEMORY_H)
check_include_file (nan.h HAVE_NAN_H)
check_include_file (ndir.h HAVE_NDIR_H)
check_include_file (netdb.h HAVE_NETDB_H)
check_include_file (process.h HAVE_PROCESS_H)
check_include_file (pthread.h HAVE_PTHREAD_H)
check_include_file (pwd.h HAVE_PWD_H)
check_include_file (regex.h HAVE_REGEX_H)
check_include_file (rxposix.h HAVE_RXPOSIX_H)
check_include_file (rx/rxposix.h HAVE_RX_RXPOSIX_H)
check_include_file (stdint.h HAVE_STDINT_H)
check_include_file (stdio.h HAVE_STDIO_H)
check_include_file (stdlib.h HAVE_STDLIB_H)
check_include_file (strings.h HAVE_STRINGS_H)
check_include_file (string.h HAVE_STRING_H)
check_include_file (sys/dir.h HAVE_SYS_DIR_H)
check_include_file (sys/file.h HAVE_SYS_FILE_H)
check_include_file (sys/ioctl.h HAVE_SYS_IOCTL_H)
check_include_file (sys/ndir.h HAVE_SYS_NDIR_H)
check_include_file (sys/param.h HAVE_SYS_PARAM_H)
check_include_file (sys/resource.h HAVE_SYS_RESOURCE_H)
check_include_file (sys/select.h HAVE_SYS_SELECT_H)
check_include_file (sys/stat.h HAVE_SYS_STAT_H)
check_include_file (sys/stdtypes.h HAVE_SYS_STDTYPES_H)
check_include_file (sys/timeb.h HAVE_SYS_TIMEB_H)
check_include_file (sys/times.h HAVE_SYS_TIMES_H)
check_include_file (sys/time.h HAVE_SYS_TIME_H)
check_include_file (sys/types.h HAVE_SYS_TYPES_H)
check_include_file (sys/utime.h HAVE_SYS_UTIME_H)
check_include_file (sys/utsname.h HAVE_SYS_UTSNAME_H)
check_include_file (sys/wait.h HAVE_SYS_WAIT_H)
check_include_file (time.h HAVE_TIME_H)
check_include_file (unistd.h HAVE_UNISTD_H)
check_include_file (utime.h HAVE_UTIME_H)
check_include_file (winsock2.h HAVE_WINSOCK2_H)
check_include_file (argz.h HAVE_ARGZ_H)
check_include_file (ctype.h HAVE_CTYPE_H)
check_include_file (errno.h HAVE_ERRNO_H)
include (CheckFunctionExists)
check_function_exists (acosh HAVE_ACOSH)
check_function_exists (alloca HAVE_ALLOCA)
check_function_exists (asinh HAVE_ASINH)
check_function_exists (atanh HAVE_ATANH)
check_function_exists (atexit HAVE_ATEXIT)
check_function_exists (bcopy HAVE_BCOPY)
check_function_exists (cexp HAVE_CEXP)
check_function_exists (chown HAVE_CHOWN)
check_function_exists (chroot HAVE_CHROOT)
check_function_exists (chsize HAVE_CHSIZE)
check_function_exists (clog HAVE_CLOG)
check_function_exists (clog10 HAVE_CLOG10)
check_function_exists (connect HAVE_CONNECT)
check_function_exists (copysign HAVE_COPYSIGN)
check_function_exists (crypt HAVE_CRYPT)
check_function_exists (ctermid HAVE_CTERMID)
check_function_exists (cuserid HAVE_CUSERID)
check_function_exists (dcgettext HAVE_DCGETTEXT)
check_function_exists (cuserid HAVE_DECL_CUSERID)
check_function_exists (DINFINITY HAVE_DINFINITY)
check_function_exists (DQNAN HAVE_DQNAN)
check_function_exists (endhostent HAVE_ENDHOSTENT)
check_function_exists (endnetent HAVE_ENDNETENT)
check_function_exists (endprotoent HAVE_ENDPROTOENT)
check_function_exists (endservent HAVE_ENDSERVENT)
check_function_exists (fchown HAVE_FCHOWN)
check_function_exists (fcntl HAVE_FCNTL)
check_function_exists (fesetround HAVE_FESETROUND)
check_function_exists (finite HAVE_FINITE)
check_function_exists (flock HAVE_FLOCK)
check_function_exists (fork HAVE_FORK)
check_function_exists (ftime HAVE_FTIME)
check_function_exists (ftruncate HAVE_FTRUNCATE)
check_function_exists (getcwd HAVE_GETCWD)
check_function_exists (geteuid HAVE_GETEUID)
check_function_exists (getgrent HAVE_GETGRENT)
check_function_exists (getgroups HAVE_GETGROUPS)
check_function_exists (gethostbyname HAVE_GETHOSTBYNAME)
check_function_exists (gethostent HAVE_GETHOSTENT)
check_function_exists (gethostname HAVE_GETHOSTNAME)
check_function_exists (getitimer HAVE_GETITIMER)
check_function_exists (getnetbyaddr HAVE_GETNETBYADDR)
check_function_exists (getnetbyname HAVE_GETNETBYNAME)
check_function_exists (getnetent HAVE_GETNETENT)
check_function_exists (getpass HAVE_GETPASS)
check_function_exists (getpgrp HAVE_GETPGRP)
check_function_exists (getppid HAVE_GETPPID)
check_function_exists (getpriority HAVE_GETPRIORITY)
check_function_exists (getprotoent HAVE_GETPROTOENT)
check_function_exists (getpwent HAVE_GETPWENT)
check_function_exists (getservent HAVE_GETSERVENT)
check_function_exists (gettext HAVE_GETTEXT)
check_function_exists (gettimeofday HAVE_GETTIMEOFDAY)
check_function_exists (gmtime_r HAVE_GMTIME_R)
check_function_exists (hstrerror HAVE_HSTRERROR)
check_function_exists (iconv HAVE_ICONV)
check_function_exists (index HAVE_INDEX)
check_function_exists (inet_aton HAVE_INET_ATON)
check_function_exists (inet_lnaof HAVE_INET_LNAOF)
check_function_exists (inet_makeaddr HAVE_INET_MAKEADDR)
check_function_exists (inet_netof HAVE_INET_NETOF)
check_function_exists (inet_ntop HAVE_INET_NTOP)
check_function_exists (inet_pton HAVE_INET_PTON)
check_function_exists (ioctl HAVE_IOCTL)
check_function_exists (isblank HAVE_ISBLANK)
check_function_exists (kill HAVE_KILL)
check_function_exists (link HAVE_LINK)
check_function_exists (lstat HAVE_LSTAT)
check_function_exists (memcpy HAVE_MEMCPY)
check_function_exists (memmove HAVE_MEMMOVE)
check_function_exists (mkdir HAVE_MKDIR)
check_function_exists (mknod HAVE_MKNOD)
check_function_exists (mkstemp HAVE_MKSTEMP)
check_function_exists (nice HAVE_NICE)
check_function_exists (on_exit HAVE_ON_EXIT)
check_function_exists (pause HAVE_PAUSE)
check_function_exists (pipe HAVE_PIPE)
#check_function_exists (pthread_attr_getstack HAVE_PTHREAD_ATTR_GETSTACK)
#check_function_exists (pthread_getattr_np HAVE_PTHREAD_GETATTR_NP)
#check_function_exists (pthread_get_stackaddr_np HAVE_PTHREAD_GET_STACKADDR_NP)
#check_function_exists (pthread_sigmask HAVE_PTHREAD_SIGMASK)
check_function_exists (putenv HAVE_PUTENV)
check_function_exists (readdir64_r HAVE_READDIR64_R)
check_function_exists (readdir_r HAVE_READDIR_R)
check_function_exists (readdir HAVE_READDIR)
check_function_exists (readlink HAVE_READLINK)
check_function_exists (rename HAVE_RENAME)
check_function_exists (rindex HAVE_RINDEX)
check_function_exists (rmdir HAVE_RMDIR)
check_function_exists (select HAVE_SELECT)
check_function_exists (setegid HAVE_SETEGID)
check_function_exists (seteuid HAVE_SETEUID)
check_function_exists (setgroups HAVE_SETGROUPS)
check_function_exists (sethostent HAVE_SETHOSTENT)
check_function_exists (sethostname HAVE_SETHOSTNAME)
check_function_exists (setitimer HAVE_SETITIMER)
check_function_exists (setlocale HAVE_SETLOCALE)
check_function_exists (setnetent HAVE_SETNETENT)
check_function_exists (setpgid HAVE_SETPGID)
check_function_exists (setpriority HAVE_SETPRIORITY)
check_function_exists (setprotoent HAVE_SETPROTOENT)
check_function_exists (setpwent HAVE_SETPWENT)
check_function_exists (setservent HAVE_SETSERVENT)
check_function_exists (setsid HAVE_SETSID)
check_function_exists (sigaction HAVE_SIGACTION)
check_function_exists (siginterrupt HAVE_SIGINTERRUPT)
check_function_exists (sincos HAVE_SINCOS)
check_function_exists (socketpair HAVE_SOCKETPAIR)
check_function_exists (stat64 HAVE_STAT64)
check_function_exists (strrchr HAVE_STRRCHR)
check_function_exists (strchr HAVE_STRCHR)
check_function_exists (strcmp HAVE_STRCMP)
check_function_exists (strdup HAVE_STRDUP)
check_function_exists (strerror HAVE_STRERROR)
check_function_exists (strftime HAVE_STRFTIME)
check_function_exists (strncasecmp HAVE_STRNCASECMP)
check_function_exists (strptime HAVE_STRPTIME)
check_function_exists (symlink HAVE_SYMLINK)
check_function_exists (sync HAVE_SYNC)
check_function_exists (sysconf HAVE_SYSCONF)
check_function_exists (system HAVE_SYSTEM)
check_function_exists (tcgetpgrp HAVE_TCGETPGRP)
check_function_exists (tcsetpgrp HAVE_TCSETPGRP)
check_function_exists (times HAVE_TIMES)
check_function_exists (trunc HAVE_TRUNC)
check_function_exists (truncate HAVE_TRUNCATE)
check_function_exists (ttyname HAVE_TTYNAME)
check_function_exists (tzset HAVE_TZSET)
check_function_exists (uname HAVE_UNAME)
check_function_exists (unsetenv HAVE_UNSETENV)
check_function_exists (usleep HAVE_USLEEP)
check_function_exists (waitpid HAVE_WAITPID)
check_function_exists (_NSGetEnviron HAVE__NSGETENVIRON)
check_function_exists (opendir HAVE_OPENDIR)
check_function_exists (_pipe HAVE__PIPE)
check_function_exists (argz_append HAVE_ARGZ_APPEND)
check_function_exists (argz_create_sep HAVE_ARGZ_CREATE_SEP)
check_function_exists (argz_insert HAVE_ARGZ_INSERT)
check_function_exists (argz_next HAVE_ARGZ_NEXT)
check_function_exists (closedir HAVE_CLOSEDIR)
check_function_exists (dlerror HAVE_DLERROR)
check_function_exists (getlogin HAVE_GETLOGIN)
include(CheckSymbolExists)
check_symbol_exists(cuserid "stdio.h" HAVE_DECL_CUSERID)
check_symbol_exists(flock "sys/file.h" HAVE_DECL_FLOCK)
check_symbol_exists(hstrerror "sys/socket.h" HAVE_DECL_HSTRERROR)
check_symbol_exists(sethostname "unistd.h" HAVE_DECL_SETHOSTNAME)
check_symbol_exists(strncasecmp "strings.h" HAVE_DECL_STRNCASECMP)
check_symbol_exists(strptime "time.h" HAVE_DECL_STRPTIME)
check_symbol_exists(tzname "time.h" HAVE_DECL_TZNAME)
check_symbol_exists(unsetenv "stdlib.h" HAVE_DECL_UNSETENV)
check_symbol_exists(vsnprintf "stdio.h" HAVE_DECL_VSNPRINTF)
check_symbol_exists(h_errno "netdb.h" HAVE_H_ERRNO)
check_symbol_exists(isinf "math.h" HAVE_ISINF)
check_symbol_exists(isnan "math.h" HAVE_ISNAN)
check_symbol_exists(struct tm "sys/time.h" TM_IN_SYS_TIME)
check_symbol_exists(S_ISLNK "sys/stat.h" HAVE_S_ISLNK)
# FIXME: Looking for pthread_getattr_np - not found
check_symbol_exists(pthread_attr_getstack "pthread.h" HAVE_PTHREAD_ATTR_GETSTACK)
check_symbol_exists(pthread_getattr_np "pthread.h" HAVE_PTHREAD_GETATTR_NP)
check_symbol_exists(pthread_get_stackaddr_np "pthread.h" HAVE_PTHREAD_GET_STACKADDR_NP)
check_symbol_exists(pthread_sigmask "pthread.h" HAVE_PTHREAD_SIGMASK)
include(CheckCSourceCompiles)
check_c_source_compiles("
#include <threads.h>
#include <time.h>
int main() {
struct timespec t;
return 0;
}
"
        HAVE_STRUCT_TIMESPEC
        )
check_c_source_compiles("
#include <errno.h>
int main() {
error_t t;
return 0;
}
"
        HAVE_ERROR_T
        )
check_c_source_compiles("
int main() {
long long t;
return 0;
}
"
        HAVE_LONG_LONGS
        )
check_c_source_compiles("
#include <stdio.h>
#include <stddef.h>
#include <stdint.h>
int main() {
ptrdiff_t t;
return 0;
}
"
        HAVE_PTRDIFF_T
        )
check_c_source_compiles("
#include <stdio.h>
#include <stddef.h>
#include <stdint.h>
int main() {
uintptr_t t;
return 0;
}
"
        HAVE_UINTPTR_T
        )
include(CheckStructHasMember)
CHECK_STRUCT_HAS_MEMBER("struct sockaddr_in6" sin6_scope_id sys/socket.h HAVE_SIN6_SCOPE_ID LANGUAGE C)
CHECK_STRUCT_HAS_MEMBER("struct sockaddr_in6" sin6_len sys/socket.h HAVE_STRUCT_SOCKADDR_IN6_SIN6_LEN LANGUAGE C)
CHECK_STRUCT_HAS_MEMBER("struct sockaddr" sin_len sys/socket.h HAVE_STRUCT_SOCKADDR_SIN_LEN LANGUAGE C)
CHECK_STRUCT_HAS_MEMBER("struct stat" st_blksize sys/stat.h HAVE_STRUCT_STAT_ST_BLKSIZE LANGUAGE C)
CHECK_STRUCT_HAS_MEMBER("struct stat" st_blocks sys/stat.h HAVE_STRUCT_STAT_ST_BLOCKS LANGUAGE C)
CHECK_STRUCT_HAS_MEMBER("struct stat" st_rdev sys/stat.h HAVE_STRUCT_STAT_ST_RDEV LANGUAGE C)
CHECK_STRUCT_HAS_MEMBER("struct tm" tm_gmtoff time.h HAVE_STRUCT_TM_TM_GMTOFF LANGUAGE C)
CHECK_STRUCT_HAS_MEMBER("struct tm" tm_zone time.h HAVE_STRUCT_TM_TM_ZONE LANGUAGE C)
CHECK_STRUCT_HAS_MEMBER("struct tm" tm_zone time.h HAVE_TM_ZONE LANGUAGE C)
CHECK_STRUCT_HAS_MEMBER("struct tm" tzname time.h HAVE_TZNAME LANGUAGE C)
include(CheckLibraryExists)
if(HAVE_TIME_H AND HAVE_SYS_TIME_H)
    set(TIME_WITH_SYS_TIME 1)
endif()
# TODO: Check?
set(STDC_HEADERS ${HAVE_STDLIB_H})
set(HAVE_IPV6 1)
set(HAVE_LIBGMP 1)
set(HAVE_LIBLTDL 1)
set(HAVE_LIBM 1)
if (WIN32)
    set(HAVE_LIBREGEX 1)
    set(HAVE_LIBWS2_32 1)
endif ()
#set(HAVE_LIBNSL 0)
#set(HAVE_LIBREGEX 0)
#set(HAVE_LIBRX 0)
#set(HAVE_LIBSOCKET 0)
#set(HAVE_LIBUCA 0)
#set(HAVE_LIBWS2_32 0)
set(HAVE_NETWORKING 1)
set(HAVE_POSIX 1)
#set(HAVE_PTHREAD 0)
set(HAVE_REGCOMP 1)
set(HAVE_STRUCT_LINGER 1)
if (UNIX)
    set(HAVE_UNIX_DOMAIN_SOCKETS 1)
    set(HAVE_LIBC_STACK_END 1)
endif ()
set(HAVE_USABLE_CSQRT 1)

set(SCM_I_GSC_GUILE_DEBUG 0)
set(SCM_I_GSC_GUILE_DEBUG_FREELIST 0)
set(SCM_I_GSC_ENABLE_DISCOURAGED 1)
set(SCM_I_GSC_ENABLE_DEPRECATED 1)
set(SCM_I_GSC_ENABLE_ELISP 1)
set(SCM_I_GSC_STACK_GROWS_UP 0)
set(SCM_I_GSC_C_INLINE "inline")
set(SCM_I_GSC_NEEDS_STDINT_H 1)
set(SCM_I_GSC_NEEDS_INTTYPES_H 0)
set(SCM_I_GSC_T_INT8 "int8_t")
set(SCM_I_GSC_T_UINT8 "uint8_t")
set(SCM_I_GSC_T_INT16 "int16_t")
set(SCM_I_GSC_T_UINT16 "uint16_t")
set(SCM_I_GSC_T_INT32 "int32_t")
set(SCM_I_GSC_T_UINT32 "uint32_t")
set(SCM_I_GSC_T_INT64 "int64_t")
set(SCM_I_GSC_T_UINT64 "uint64_t")
set(SCM_I_GSC_T_INTMAX "intmax_t")
set(SCM_I_GSC_T_UINTMAX "uintmax_t")
set(SCM_I_GSC_T_PTRDIFF "ptrdiff_t")
# FIXME: undefined reference to `scm_init_guile'
set(SCM_I_GSC_USE_PTHREAD_THREADS 0)
set(SCM_I_GSC_USE_NULL_THREADS 1)
set(SCM_I_GSC_NEED_BRACES_ON_PTHREAD_ONCE_INIT 0)
set(SCM_I_GSC_NEED_BRACES_ON_PTHREAD_MUTEX_INITIALIZER 0)
set(SCM_I_GSC_HAVE_STRUCT_DIRENT64 1)